/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haipv.gtkhoa501.screen;

import com.haipv.gtkhoa501.controller.Event;
import com.haipv.gtkhoa501.model.Var;
import com.nokia.lwuit.components.HeaderBar;
import com.sun.lwuit.Button;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.List;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.list.DefaultListModel;
import com.sun.lwuit.list.ListModel;
import java.io.IOException;
import java.util.Vector;

/**
 *
 * @author PHANHAI
 * Giao diện chính, lụa chọn các chức năng biển báo, ôn tập, làm bài thi
 */
public class MainScreen extends BaseScreen implements ActionListener {

    ListModel model;
    List list;
    Command commanAbout;
    Command commanHelp;

    public MainScreen() {
        controller.SetFullScreen();
        commanAbout = new Command(Var.about);
        commanHelp = new Command(Var.help);
        Var.tap = 1;
        if (controller.categoryBarReview.getVisibility() == true) {
            controller.categoryBarReview.setVisibility(false);
        }
        if (controller.categoryBarExam.getVisibility() == true) {
            controller.categoryBarExam.setVisibility(false);
        }
        if (controller.categoryBarExamReview.getVisibility() == true) {
            controller.categoryBarExamReview.setVisibility(false);
        }
  
        Font font = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
        //Form form = new Form();
        setScrollable(false);
        //form.setTitle("Luật giao thông");
        HeaderBar header = null;
        try {
            header = new HeaderBar("Luật giao thông");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        header.setHeaderTitleColor(Var.colorHearder);
        header.getStyle().setBgColor(Var.colorWhite);


        header.setScrollable(false);

        addComponent(header);

        model = new DefaultListModel();


        for (int i = 0; i < 3; i++) {
            Command item = null;
            try {
                item = new Command(Var.menu[i], Image.createImage("/images/nen/aanh" + (i + 1) + ".png"));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            if (null != item) {
                model.addItem(item);
            }
        }


        list = new List(model);
        list.getStyle().setFont(font);
        //list.getStyle().setPadding(0, 0, 10, 10);

        Container con = new Container();
        con.addComponent(list);
        con.getStyle().setMargin(10, 20, 17, 17);

        addComponent(con);
        list.addActionListener(this);
        setDefaultCommand(commanHelp);
        setDefaultCommand(commanAbout);
        
        addCommand(commanHelp);
        addCommand(commanAbout);
        addCommandListener(this);
        

    }

    public void actionPerformed(ActionEvent ae) {
        if (ae.getCommand() == commanAbout) {
            controller.handleEvent(Event.ABOUT_ACTION, null);
        } else if (ae.getCommand() == commanHelp) {
            controller.handleEvent(Event.HELP_ACTION, null);
        } else if (ae.getSource() == list) {
            if (list.getSelectedIndex() == 1) {
                controller.handleEvent(Event.SIGN_VIEW, null);
            } else if (list.getSelectedIndex() == 0) {
                Event evt = new Event();
                evt.setKey("INDEX", Var.indexReview + "");
                controller.handleEvent(Event.REVIEW_SEEK, evt);
            } else if (list.getSelectedIndex() == 2) {
                Event evt = new Event();
                Var.indexExam = 1;
                evt.setKey("INDEX", Var.indexExam + "");
                controller.handleEvent(Event.EXAM_ACTION, evt);
            }
        }
    }
}
